//TODO a(40)
function a40(module, exports, a) {
    var i = a(23), s = a(3), r = a(21), n = a(2), o = function () {
    };
    s.extend(o, i);
    var l = {
        init: function () {
            this.playerData = this.manager.playerData,
                this.currIdx = 0, this.movieVO = null, this.targetDefi = 0,
                this.isForceDefi = !1,
                this.param = ["format=1", "jsonp=?", "expect=3",
                    "p1=" + this.playerData.config.p1,
                    "p2=" + this.playerData.config.p2,
                    "termid=2",
                    "ostype=" + (n.Android && "android" || n.mac && "macos" || n.Window && "windows"
                    || n.Linux && "linux" || "un"),
                    "hwtype=" + (n.iPhone && "iphone" || n.iPad && "ipad" || n.LetvX60 && "X60"
                    || n.LetvX40 && "X40" || "un")],
                this.manager.listener.on(r.PLAY_STATE, this.onPlayStateChange, this)
        }, onPlayStateChange: function (e, t) {
            "init" == t ? (this.currIdx = 0, this.movieVO = null, this.targetDefi = 0, this.isForceDefi = !1) : "changeDefi" == t && (this.currIdx = 0)
        }, setMovieVO: function (e) {
            this.movieVO = e
        }, getGslb: function (e, t) {
            if (this.targetDefi = e, this.isForceDefi = t, "none" == this.playerData.tryLookType && this.playerData.vinfo.ispay) {
                var a = this.playerData.validateInfo || {};
                if (e == this.playerData.config.defi && a.token) this.getData({token: a.token}), delete a.token; else {
                    var i = this.movieVO[this.targetDefi].storePath;
                    this.manager.user.getToken(i, s.bind(function (e) {
                        this.getData({token: e})
                    }, this), s.bind(function () {
                        this.manager.pingback.sendError(r.ERROR_CODE.TOKEN_TIMEOUT)
                    }, this))
                }
            } else this.getData()
        }, getData: function (e) {
            e = e || {};
            var t = this.movieVO[this.targetDefi].urls;
            if (this.currIdx >= t.length)return void this.sendError(r.ERROR_CODE.GSLB_TIMEOUT);
            var a = t[this.currIdx], i = this.manager.listener.get(r.USER_INFO);
            e.token && (a += "&token=" + e.token + "&uid=" + i.ssouid),
            "appGuide" == this.playerData.tryLookType && this.playerData.tryLookTime
            && (a += "&cutoff=" + this.playerData.tryLookTime),
                a += "&" + this.param.join("&"), a += "&uuid=" + this.manager.pingback.getUUID(),
                a += "&vid=" + this.playerData.vinfo.vid, n.letvMobile && (a += "&devn=lephone"),
                this.playerData.config.supportP2P ? (a = a.replace(/jsonp=\?&/, ""),
                    this.manager.log.pushLog("vjs_p2pUrlSucc===" + a),
                    this.manager.evt.trigger("vjs_p2pUrlSucc", a, this.targetDefi)) :
                    (this.manager.log.pushLog("getGslb: "), this.jsonp = s.getJSON({
                        url: a,
                        log: this.manager.log,
                        maxCount: 1,
                        success: s.bind(this.onGslbSucc, this),
                        fail: s.bind(this.onGslbFail, this)
                    }))
        }, onGslbSucc: function (e) {
            if (this.jsonp = null, this.manager.log.pushLog("gslbSuc: " + s.JSONTOStr(e)), 445 == e.ercode || e.playlevel >= 3 && !this.isForceDefi) {
                this.isForceDefi && this.manager.evt.trigger("showTip", "glsbPressure");
                var t, a = this.movieVO;
                if (a[1] ? t = "1" : a[2] ? t = "2" : a[3] && (t = "3"), t && this.targetDefi != t)return void this.manager.evt.trigger(r.EVENT.PLAYER_COMMAND, "changeDefi", t)
            }
            if (0 != e.ercode && 445 != e.ercode)switch (e.ercode) {
                case 444:
                    this.sendError(r.ERROR_CODE.GSLB_SERVER_PRESSURE_LARGE);
                    break;
                case 424:
                    this.manager.evt.trigger("vjs_gslbFail");
                    break;
                default:
                    this.sendError(r.ERROR_CODE.GSLB_ERROR)
            } else if (e.nodelist && e.nodelist.length > 0) {
                for (var i = [], n = e.nodelist, o = 0, l = n.length; o < l; o++)n[o].location && i.push(n[o].location);
                this.manager.evt.trigger("vjs_gslbSuccess", i, this.targetDefi, {
                    responseTime: arguments[1].responseTime,
                    retryCount: arguments[1].retryCount
                })
            } else this.sendError(r.ERROR_CODE.GSLB_DATA_EMPTY)
        }, onGslbFail: function () {
            this.jsonp = null, this.manager.log.pushLog("gslb fail"), this.currIdx++, this.getData()
        }
    };
    s.merge(o.prototype, l), module.exports = o
}
